#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 205;

int k, x;
ll fastpow(ll b, ll p, ll mod) {
  ll res = 1;
  while (p) {
    if (p & 1) res = res * b % mod;
    b = b * b % mod;
    p >>= 1;
  }
  return res;
}
int C[1005][105][N];
void add(int a[N], int b[N], int c[N]) {
  rep(i, 0, 200) c[i] = a[i] + b[i];
  rep(i, 0, 200) c[i + 1] += c[i] / 10, c[i] %= 10;
}
void out(int a[N]) {
  int h = 200;
  while (h > 0 && a[h] == 0) h--;
  while (h >= 0) cout << a[h--];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> x;
  int n = fastpow(x % 1000, x, 1000);
  rep(i, 0, n) rep(j, 0, min(i, k)) {
    if (j == 0) {
      C[i][j][0] = 1;
      continue;
    }
    add(C[i - 1][j - 1], C[i - 1][j], C[i][j]);
  }
  out(C[n - 1][k - 1]);
  return 0;
}